<?php
function arrayRecursive(&$array, $function, $apply_to_keys_also = false) {
	if ($array != null) {
		foreach ( $array as $key => $value ) {
			if (is_array ( $value )) {
				arrayRecursive ( $array [$key], $function, $apply_to_keys_also );
			} else {
				$array [$key] = $function ( $value );
			}
			
			if ($apply_to_keys_also && is_string ( $key )) {
				$new_key = $function ( $key );
				if ($new_key != $key) {
					$array [$new_key] = $array [$key];
					unset ( $array [$key] );
				}
			}
		}
	}
}
function JSON($array) {
	arrayRecursive ( $array, 'urlencode', true );
	$json = json_encode ( $array );
	return urldecode ( $json );
}
function format_search_url($search) {
	$url = "";
	if ($search) {
		foreach ( $search as $key => $val ) {
			if (is_array ( $val )) {
				foreach ( $val as $v ) {
					$url .= $key . "[]=" . $v . "&";
				}
			} else {
				$url .= $key . "=" . $val . "&";
			}
		}
		$url = substr ( $url, 0, - 1 );
	}
	return $url;
}
function getDataURI($image, $mime = '') {
	if (file_exists ( $image )) {
		return 'data:image/jpeg;base64,' . base64_encode ( file_get_contents ( $image ) );
	}
}
function get_agreement_id($agreement) {
	$id = 0;
	if ($agreement == "待确认") {
		$id = 0;
	} elseif ($agreement == "政府批文") {
		$id = 10;
	} elseif ($agreement == "场租协议") {
		$id = 20;
	} elseif ($agreement == "采购合同") {
		$id = 30;
	}
	return $id;
}